﻿using ExcelToEntity.Models;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ExcelToEntity
{
    /// <summary>
    /// 生成实体模板
    /// </summary>
    public static class EntityTemplate
    {
        private static StringBuilder sb = new StringBuilder();

        /// <summary>
        /// 添加注释
        /// </summary>
        /// <param name="desc"></param>
        private static void AddDesc(string desc)
        {
            sb.Append($"/// <summary>\r\n/// {desc}\r\n/// </summary>\r\n");
            return;
        }

        /// <summary>
        /// 创建实体
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public static string CreateEntity(IEnumerable<ExcelModel> rows)
        {
            sb.Clear();
            foreach (var row in rows)
            {
                if (string.IsNullOrEmpty(row.DataName))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(row.Description))
                {
                    sb.Append($"public {row.DataType} {row.DataName} " + "{get;set;}\r\n\r\n");
                }
                else
                {
                    AddDesc(row.Description);
                    sb.Append($"public {row.DataType} {row.DataName} " + "{get;set;}\r\n\r\n");
                }
            }
            return sb.ToString();
        }
    }
}
